package main.java.ensao.cryptography.rsaattack;

import java.math.BigInteger;

import main.java.ensao.cryptography.rsamodule.Utils;

public class ModuleCommun {

	
	public static int val_u;
	public static int val_v;
	static int val_d;
	
	
	
	 public static void calc_bezout(BigInteger bigInteger, BigInteger bigInteger2) {
         BigInteger d,q,u,v,w,x,y,z,aBis,bBis;
         aBis = bigInteger;
         bBis = bigInteger2;
         u = BigInteger.ONE;
         v = BigInteger.ZERO;
         w = BigInteger.ZERO;
         x = BigInteger.ONE;
         y = BigInteger.ZERO;
         
         if (bigInteger2.compareTo(BigInteger.ZERO) < 0)
                 y = BigInteger.ONE;
         
         while (bigInteger2.compareTo(BigInteger.ZERO) != 0) {
                 q = bigInteger.divide(bigInteger2);
                 z = u;
                 u = w;
                 w = z.subtract(q.multiply(w));
                 z = v;
                 v = x;
                 x = z.subtract(q.multiply(x));
                 z = bigInteger;
                 bigInteger = bigInteger2;
                 bigInteger2 = z.subtract(q.multiply(bigInteger2));
         }
         
         if (y.compareTo(BigInteger.ONE) == 0) {
                 u = u.negate();
                 v = v.negate();
         }
         
         d = aBis.multiply(u).add(bBis.multiply(v));
         val_u = u.intValue();
         val_v = v.intValue();
         val_d = d.intValue();
         
      
	 }
	 
	 
	public static int calcul_m(int n , int c1, int c2){
		int part1 , part2 , result = 0;
		if(val_d == 1){
		
		System.out.println(val_u);
		System.out.println(val_d);
		part1 = Utils.exponenciation_rapide(c1, val_u, n);
		part2 = Utils.exponenciation_rapide(c2, val_v, n);
		
		System.out.println("hnaa");
		return part1*part2;
		}
		
		return 0;
		
	}
	
	
	
}
